package com.nengchuan.kbms.dfs.controller.work;


import com.nengchuan.config.build.AuthUtils;
import com.nengchuan.excel.util.CsncExcelUtil;
import com.nengchuan.kbms.dfs.entity.dto.FlowCreateListDTO;
import com.nengchuan.kbms.dfs.entity.dto.FlowCreatePageDTO;
import com.nengchuan.kbms.dfs.entity.dto.FlowVerifyListDTO;
import com.nengchuan.kbms.dfs.entity.dto.FlowVerifyPageDTO;
import com.nengchuan.kbms.dfs.entity.vo.TmpFlowCreateVO;
import com.nengchuan.kbms.dfs.entity.vo.TmpFlowVerifyVO;
import com.nengchuan.kbms.dfs.service.TmpFlowService;
import com.nengchuan.model.model.NcPageInfo;
import com.nengchuan.model.model.WrappedResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 流程管理 前端控制器
 * </p>
 *
 * @author abe
 * @since 2020-04-10
 */
@RestController
@RequestMapping("/work/flow")
@Api(tags = "知识库数据后台管理 > 工作管理 > 流程管理 > 我的发起、我的流程审批列表 【已完成】")
public class FlowController {

    @Autowired
    private TmpFlowService tmpFlowService;

//    @PostMapping("/save")
//    @ApiOperation(value = "保存【前端忽略】")
//    public WrappedResult<Long> save(@RequestBody TmpFlow flow) {
//        return WrappedResult.success(tmpFlowService.insert(flow).getId());
//    }

    @PostMapping("/create/page")
    @ApiOperation(value = "我的发起-列表")
    public WrappedResult<NcPageInfo<TmpFlowCreateVO>> createPage(@RequestBody FlowCreatePageDTO pageDTO) {
        pageDTO.setCreateId(AuthUtils.getUserId());
        return WrappedResult.success(tmpFlowService.page(pageDTO, TmpFlowCreateVO.class));
    }

    @PostMapping(value = "/create/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ApiOperation(value = "我的发起-导出列表")
    public void createExport(@RequestBody FlowCreateListDTO listDTO, HttpServletResponse response) throws Exception {
        listDTO.setCreateId(AuthUtils.getUserId());
        List<TmpFlowCreateVO> list = tmpFlowService.list(listDTO, TmpFlowCreateVO.class);
        CsncExcelUtil.export(list, TmpFlowCreateVO.class, response, "我的发起列表.xls");
    }

    @PostMapping("/verify/page")
    @ApiOperation(value = "我的审批-列表")
    public WrappedResult<NcPageInfo<TmpFlowVerifyVO>> verifyPage(@RequestBody FlowVerifyPageDTO pageDTO) {
        pageDTO.setVerifyId(AuthUtils.getUserId());
        return WrappedResult.success(tmpFlowService.page(pageDTO, TmpFlowVerifyVO.class));
    }

    @PostMapping(value = "/verify/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @ApiOperation(value = "我的审批-导出列表")
    public void verifyExport(@RequestBody FlowVerifyListDTO listDTO, HttpServletResponse response) throws Exception {
        listDTO.setVerifyId(AuthUtils.getUserId());
        List<TmpFlowVerifyVO> list = tmpFlowService.list(listDTO, TmpFlowVerifyVO.class);
        CsncExcelUtil.export(list, TmpFlowVerifyVO.class, response, "我的审批列表.xls");
    }

}
